class Solution:
    def removeInvalidParentheses(self, s):
        ret = set()
        acc = []
        class Context:
            maxLen = 0
        def find(begin, dif):
            if dif<0: return
            elif dif==0 and len(acc)>=Context.maxLen: 
                ret.add(''.join(acc))
                Context.maxLen = len(acc)
            
            if begin==len(s): return
            
            c = s[begin]
            if c=='(':
                acc.append(c)
                find(begin+1, dif+1)
                acc.pop()
                find(begin+1, dif)
            elif c==')': 
                acc.append(c)
                find(begin+1, dif-1)
                acc.pop()
                find(begin+1, dif)
            else:
                acc.append(c)
                find(begin+1, dif)
                acc.pop()
        find(0, 0)
        return list(filter(lambda x:len(x)==Context.maxLen, ret))

print(Solution().removeInvalidParentheses(')('))